<!DOCTYPE html>
<html lang="zh-cn">

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="{{ asset('admin_style/css/pintuer.css') }}">
   <link rel="stylesheet" href="{{ asset('admin_style/css/admin.css') }}">
    <script src="{{asset('admin_style/js/jquery.js')}}"></script>
    <script src="{{asset('admin_style/js/pintuer.js')}}"></script>

</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong><span class="icon-key"></span> 绑定手机号</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="{{ url('home/get_phone')}}">
    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
     @if($data->u_phone)
      <div class="form-group">
        <div class="label">
          <label for="sitename">当前手机号：</label>
        </div>
        <div class="field">
          <label style="line-height:33px;">{{$data->u_phone}}</label>
        </div>
      </div>
     @endif
      <div class="form-group">
        <div class="label">
          <label for="sitename">手机号：</label>
        </div>
        <div class="field">
	 @if($errors)
          <input type="text" class="input w50" id="u_phone" name="u_phone" size="50" placeholder="请输入手机号"  value="{{$old}}"/>
	  <p id ='show_errors' style='color:red;margin-left:30px' >&nbsp&nbsp&nbsp&nbsp{{$errors}}</p>
	 @else
          <input type="text" class="input w50" id="u_phone" name="u_phone" size="50" placeholder="请输入手机号"  value=""/>
	  <p id ='show_errors' style='color:red;margin-left:30px' ></p>
	@endif
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label for="sitename">验证码：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="getCode" size="50" style="width:120px" placeholder="请输入验证码" />
	 <button class="button border-main" type="button" style="margin-left:5px"id="get_code">获取验证码</button>
        </div>
      </div>
       <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
</body></html>
<script>
   $("#get_code").on("click",bind_phone);
   function bind_phone(){
    var get_iphone=$("#u_phone").val();
    var change_time = 60;
        $.ajax({ 
                url:"{{url('home/bind_phone')}}",
                type:"post",
                data:{
                   "u_phone":get_iphone,
                   "_token": "{{ csrf_token() }}",
                  },
                dataType:"json",
                success:function(res){
			if(!res['success']){
		 	 var showData = res['errors']['u_phone'][0];
                   	 $("#show_errors").html("&nbsp&nbsp&nbsp&nbsp"+showData);
			}else{
			    $("#show_errors").html('');
			    var intervalId = setInterval(function () {
                             change_time--;
                             $("#get_code").html(change_time+"s后重发");
                             $("#get_code").attr("disabled",true); 
                             $( "#get_code" ).off( "click",bind_phone);  
                        if (change_time == 0) {
                            clearInterval(intervalId);
                            $("#get_code").html("获取验证码");
                            $("#get_code").attr("disabled",false);     
                            $("#get_code").on("click",bind_phone);   
                         }
                 }, 1000)};
			}

        });



   
}
</script>
